package com.ruoyi.wvp.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.enums.DeletedEnum;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.wvp.domain.Surveillance;
import com.ruoyi.wvp.domain.SurveillanceEvent;
import com.ruoyi.wvp.service.ISurveillanceEventService;
import com.ruoyi.wvp.service.ISurveillanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("setEventDeviceNameTask")
@Slf4j
public class SetEventDeviceNameTask {


    public void start(){
        ISurveillanceEventService surveillanceEventService = SpringUtils.getBean(ISurveillanceEventService.class);
        ISurveillanceService surveillanceService = SpringUtils.getBean(ISurveillanceService.class);
        Surveillance surveillance = new Surveillance();
        surveillance.setDeleted(DeletedEnum.NOMAL.getValue());
        List<Surveillance> surveillances = surveillanceService.selectSurveillanceList(surveillance);
        for (Surveillance surveillance1 : surveillances) {
            LambdaQueryWrapper<SurveillanceEvent> queryWrapper = Wrappers.lambdaQuery();
            queryWrapper.eq(SurveillanceEvent::getSerialNumber,surveillance1.getSerialNumber());
            SurveillanceEvent surveillanceEvent = new SurveillanceEvent();
            surveillanceEvent.setDeviceName(surveillance1.getDeviceName());
            surveillanceEventService.update(surveillanceEvent,queryWrapper);
        }

    }
}
